///////////////////////////////////////////////////////////////////////////////
//
// Licensed under the MIT License
//
// Copyright (c) 2010 Chris Colinsky
// All Rights Reserved
//
// version	0.5
// http://code.google.com/p/sugarcookie/
// http://code.google.com/p/sugarcookie/wiki/License
//
////////////////////////////////////////////////////////////////////////////////

package sugarcookie.events {
	import flash.events.Event;
	import mx.logging.Log;
	import mx.logging.ILogger;
	
	public class CollectionPropertyChangeEvent extends Event {
		public static const CHANGE:String = "onCollectionPropertyChange";
		
		public var property:String;
		public var newValue:Object;
		public var isLogable:Boolean;
		
		private var _log:ILogger;
		
		public function CollectionPropertyChangeEvent(type:String, property:String, newValue:Object, bubbles:Boolean=false, cancelable:Boolean=false, isLogable:Boolean=false):void {
			super(type, bubbles, cancelable);
			
			this.property = property;
			this.newValue = newValue;
			this.isLogable = isLogable;
			
			if (isLogable) {
				initLogger();
				postLogMsg();
			}
		}
		
		override public function clone():Event{
			return new CollectionPropertyChangeEvent(type, property, newValue, bubbles, cancelable, isLogable);
		}
		
		override public function toString():String {
			return formatToString("CollectionPropertyChangeEvent", "type", "property", "newValue", "bubbles", "cancelable", "eventPhase", "isLogable");
		}
		
		protected function initLogger():void {
			_log = Log.getLogger("sugarcookie.events.GenericEvent");
		}
		
		protected function postLogMsg():void {
			_log.debug(toString());
		}
	}
}